package com.wjs.gulimall.gulimallorder.controller;

import com.wjs.gulimall.gulimallorder.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller
public class IndexController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/{page}.html")
    public String page(@PathVariable("page")String page){
        return page;
    }

    @GetMapping("/test/createOrder")
    @ResponseBody
    public String test(){
        OrderEntity entity=new OrderEntity();
        entity.setOrderSn(UUID.randomUUID().toString().replace("-",""));
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",entity);
        return "ok";
    }
}
